<html>
<head>
<title>我的-优惠券</title>
<meta charset="utf-8">
<meta name="viewport"
	content="width=device-width,initial-scale=1,user-scalable=no">
<link href="https://res.wx.qq.com/open/libs/weui/1.1.2/weui.min.css"
	rel="stylesheet" type="text/css">
<script type="text/javascript" defer="defer" src="../../js/common.js"></script>
<script src="../../../../common/jquery-3.3.1.min.js"></script>
<script>
	var timmerFlag = 0;
	$(document).ready(function() {
		init();
	});
	var templateStr=
	"	<div class=\"weui-form-preview\">\r\n" + 
	"	<div style=\"padding-top: 10px\">${cName}：</div>\r\n" + 
	"		<div class=\"weui-form-preview__bd\" style=\"padding:10 0\">\r\n" + 
	"			<p>\r\n" + 
	"				<label class=\"weui-form-preview__label\">金额/折扣</label> <span\r\n" + 
	"					class=\"weui-form-preview__value\">${parValue}</span>\r\n" + 
	"			</p>\r\n" + 
	"			<p>\r\n" + 
	"				<label class=\"weui-form-preview__label\">有效期</label> <span\r\n" + 
	"					class=\"weui-form-preview__value\">${useTime}</span>\r\n" + 
	"			</p>\r\n" + 
	"			<p>\r\n" + 
	"				<label class=\"weui-form-preview__label\">领取时间</label> <span\r\n" + 
	"					class=\"weui-form-preview__value\">${getTime}</span>\r\n" + 
	"			</p>\r\n" + 
	"			<p>\r\n" + 
	"				<label class=\"weui-form-preview__label\">使用说明</label> <span\r\n" + 
	"					class=\"weui-form-preview__value\">${couponDesc}</span>\r\n" + 
	"			</p>\r\n" + 
	"		</div>\r\n" + 
	"	</div>\r\n";
	function init() {
		var Request = new UrlSearch();
		var code = Request.code;

		var url = "/yuea/weixin/couponAndPerson/getALL?userPageAuthCode="+ code;
		var data={};
		var couponsStr="";
		$.ajax({
			url : url,
			type : "post",
			contentType : "application/json",
			dataType : "json",
			data : JSON.stringify(data),
			success : function(response) {
				if(response.state=="BUSI_STATE_OK"){
					$("#line").css("display","none");
					$("#loadmore").css("display","none");
					var data=response.data;
					var temp;
					if(data.length==0){
						$("#nodata").css("display","block");
						return;
					}
					for(var i=0;i<data.length;i++){
						temp=data[i];
						var template=templateStr;
						template=template.replace("${cName}",temp.coupon.couponName);
						var parValue="";
						if(temp.coupon.couponType=="3"){
							parValue=temp.coupon.parValue+"折";
						}else if(temp.coupon.couponType=="1"){
							parValue="￥"+temp.coupon.parValue;
						}else if(temp.coupon.couponType=="2"){
							parValue="￥"+temp.coupon.parValue+"(满"+temp.coupon.mimimumCredit+"元使用)";
						}
						template=template.replace("${parValue}",parValue);
						var useTime="永久有效";
						if(temp.coupon.beginTime!=null && temp.coupon.endTime!=null){
							useTime=formatDate(temp.coupon.beginTime)+"~"+formatDate(temp.coupon.endTime);
						}
						template=template.replace("${useTime}",useTime);
						template=template.replace("${getTime}",formatDateTime(temp.getTime));
						template=template.replace("${couponDesc}",temp.coupon.couponDesc);
						couponsStr=couponsStr+template;
					}
					$("#couponsDiv").html(couponsStr);
				}
				var stat=response.state;
			},
			error:function(response){
				$("#line").css("display","none");
				$("#loadmore").css("display","none");
				$("#tryagain").css("display","block");
			}
		}) 

	}
</script>
</head>
<body>
	<div id="testdiv"></div>
	<div class="weui-panel__bd">
		<div class="weui-media-box weui-media-box_appmsg">
			<div class="weui-media-box__hd">
				<img class="weui-media-box__thumb"
					src=""
					alt="">
			</div>
			<div class="weui-cell__bd">
				<p>尊敬的顾客您好，欢迎光临本店，祝您生活愉快。</p>
			</div>
		</div>

		<!-- <div class="weui-cell weui-cell_access" style="margin-right: 15px">
			<span>开业酬宾代金券：</span>
		</div> -->
		<div id="couponsDiv" class="weui-panel__bd" style="margin: 0px 15px">
		</div>
		
		
		<div id="line" class="weui-loadmore weui-loadmore_line weui-loadmore_dot">
		    <span class="weui-loadmore__tips"></span>
		</div>
		
		<div id="loadmore" class="weui-loadmore">
			<i class="weui-loading"></i> <span class="weui-loadmore__tips">正在加载</span>
		</div>
		
		
		
		
		<div id="tryagain" class="weui-loadmore weui-loadmore_line" style="display: none">
		    <span class="weui-loadmore__tips">网络异常，请稍后重试</span>
		</div>
		
		<div id="nodata" class="weui-loadmore weui-loadmore_line" style="display: none">
		    <span class="weui-loadmore__tips">暂无数据</span>
		</div>

	</div>



</body>
</html>